/*
 * IsoMetrics - metrics for isometrics, ha ha (conversion functions)
 *
 * Copyright 2007 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#if flash9
import flash.geom.Point;
#else neko
import lib3f.Point;
#end
import lib3f.IntPoint;

class IsoMetrics
{

	static public function tiletopix_xy(tx : Int, ty : Int) : Point
	{
		return new Point(((680/2)-11)+(tx*11)-(ty*11),
						 (-11*6)+(tx*11+ty*11));
	}

	static public function tiletopix_xy_fine(tx : Int, ty : Int, 
											 finex : Int, finey : Int) : Point
	{
		return new Point(((680/2)-11)+(tx*11)+finex-(ty*11)-finey,
						 (-11*6)+finex+finey+(tx*11+ty*11));
	}

	static public function pixtotile_xy(sx : Float, sy: Float) : IntPoint
	{
		var tempcx: Float;
		var tempcy: Float;
		var retx : Int;
		var rety : Int;
		
		tempcx = (-((680/2))+(sx));
		tempcy = (-(-11*6)+(sy));	
				
		retx = Std.int((tempcx/2 + tempcy/2)/11);
		rety = Std.int((-tempcx/2 + tempcy/2)/11);
	
		return new IntPoint(
						retx,
						rety
						);
	
	}
	
	static public function pixtotile_point(pt : Point) : IntPoint
	{
		var tempcx: Float;
		var tempcy: Float;
		var retx : Int;
		var rety : Int;
		
		tempcx = (-((680/2))+(pt.x));
		tempcy = (-(-11*6)+(pt.y));	

		retx = Std.int((tempcx/2 + tempcy/2)/11);
		rety = Std.int((-tempcx/2 + tempcy/2)/11);
	
		return new IntPoint(
						retx,
						rety
						);
						
	}

		static public function tiletopix_point(pt : IntPoint) : Point
	{
		return new Point(((680/2)-11)+(pt.x*11)-(pt.y*11),
						 (-11*6)+(pt.x*11+pt.y*11));
	}

	static public function tilecorner_top(x : Int, y : Int) : Point
	{
		var z = tiletopix_xy(x,y);
		z.x+=12;
		return z;
	}

	static public function tilecorner_left(x : Int, y : Int) : Point
	{
		var z = tiletopix_xy(x,y+1);
		z.x+=12;
		return z;
	}

	static public function tilecorner_right(x : Int, y : Int) : Point
	{
		var z = tiletopix_xy(x+1,y);
		z.x+=12;
		return z;
	}

	static public function tilecorner_bottom(x : Int, y : Int) : Point
	{
		var z = tiletopix_xy(x+1,y+1);
		z.x+=12;
		return z;
	}
	
}
